﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using Microsoft.AspNetCore.Mvc;
using BCDto.OA.BusinessFlowPushRecord;
using BCService.Utils;
using BCService.OA.BusinessFlowPushRecord;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.BusinessFlowPushRecord
{
    /// <summary>
    /// OA系统业务流推进记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class BusinessFlowPushRecordController : ManagementBaseController
    {
        private readonly IBusinessFlowPushRecordService businessFlowPushRecordService;

        public BusinessFlowPushRecordController(IBusinessFlowPushRecordService businessFlowPushRecordService)
        {
            this.businessFlowPushRecordService = businessFlowPushRecordService;
        }

        #region 添加OA系统业务流推进记录
        /// <summary>
        ///  添加OA系统业务流推进记录
        /// </summary>
        /// <param name="requestDto">OA系统业务流推进记录信息</param>
        /// <response code="201">添加OA系统业务流推进记录成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加OA系统业务流推进记录")]
        [ProducesResponseType(typeof(BusinessFlowPushRecordDto), 201)]
        public IActionResult Post(
            [FromBody]BusinessFlowPushRecordRequestDto requestDto)
        {
            var result = this.businessFlowPushRecordService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/BusinessFlowPushRecord/{0}", result.BusinessFlowPushRecordId), result);
        }
        #endregion

        #region 修改OA系统业务流推进记录
        /// <summary>
        ///  修改OA系统业务流推进记录
        /// </summary>
        /// <param name="businessFlowPushRecordId">OA系统业务流推进记录Id</param>
        /// <param name="requestDto">OA系统业务流推进记录信息</param>
        /// <response code="200">修改OA系统业务流推进记录成功</response>
        /// <returns></returns>
        [HttpPut("{business_flow_push_record_id}")]
        [Log("修改OA系统业务流推进记录")]
        [ProducesResponseType(typeof(BusinessFlowPushRecordDto), 200)]
        public IActionResult Post([FromRoute(Name = "business_flow_push_record_id")]long businessFlowPushRecordId, [FromBody]BusinessFlowPushRecordRequestDto requestDto)
        {
            BusinessFlowPushRecordPutDto putDto = requestDto.As<BusinessFlowPushRecordPutDto>();
            putDto.BusinessFlowPushRecordId = businessFlowPushRecordId;
            return this.Ok(this.businessFlowPushRecordService.Update(putDto));
        }
        #endregion

        #region 删除OA系统业务流推进记录
        /// <summary>
        ///  删除OA系统业务流推进记录
        /// </summary>
        /// <param name="businessFlowPushRecordId">OA系统业务流推进记录Id</param>
        /// <response code="204">删除OA系统业务流推进记录成功</response>
        /// <returns></returns>
        [HttpDelete("{business_flow_push_record_id}")]
        [Log("删除OA系统业务流推进记录")]
        public IActionResult Delete([FromRoute(Name = "business_flow_push_record_id")]long businessFlowPushRecordId)
        {
            this.businessFlowPushRecordService.Delete(businessFlowPushRecordId);
            return this.NoContent();
        }
        #endregion

        #region 获取OA系统业务流推进记录
        /// <summary>
        ///  获取OA系统业务流推进记录
        /// </summary>
        /// <param name="businessFlowPushRecordId">OA系统业务流推进记录Id</param>
        /// <response code="200">获取OA系统业务流推进记录</response>
        /// <returns></returns>
        [HttpGet("{business_flow_push_record_id}")]
        [ProducesResponseType(typeof(BusinessFlowPushRecordDto), 200)]
        public IActionResult Get([FromRoute(Name = "business_flow_push_record_id")]long businessFlowPushRecordId)
        {
            return this.Ok(this.businessFlowPushRecordService.GetEntity(businessFlowPushRecordId));
        }
        #endregion

        #region 获取OA系统业务流推进记录列表
        /// <summary>
        ///  获取OA系统业务流推进记录列表
        /// </summary>
        /// <response code="200">获取OA系统业务流推进记录列表</response>
        /// <returns></returns>
        [HttpGet("{business_flow_model_code}/{reference_no}")]
        [ProducesResponseType(typeof(BusinessFlowPushRecordDto), 200)]
        public IActionResult GetEntity([FromRoute(Name = "business_flow_model_code")]string businessFlowModelCode,
             [FromRoute(Name = "reference_no")]string referenceNo)
        {
            return this.Ok(this.businessFlowPushRecordService.GetEntity(businessFlowModelCode, referenceNo));
        }
        #endregion

        #region 获取OA系统业务流推进记录（分页）
        /// <summary>
        ///  获取OA系统业务流推进记录（分页）
        /// </summary>
        /// <param name="businessFlowModelCode">业务流模型编码</param>
        /// <param name="referenceNo">引用编号</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取OA系统业务流推进记录（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<BusinessFlowPushRecordDto>), 200)]
        public IActionResult Query([FromQuery(Name = "business_flow_model_code")]string businessFlowModelCode,
            [FromQuery(Name = "reference_no")]string referenceNo,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.businessFlowPushRecordService.Query(businessFlowModelCode, referenceNo, start, end, pageIndex, pageSize));
        }
        #endregion
    }
}